#include <iostream>
#include "ring.hpp"
#include <pthread.h>
#include <unistd.h>
void* consumer(void* arg)
{
  auto rq=(RingQuene<int>*)arg; 
  while(1)
  {
    int out;
    rq->pop(out);
    printf("consumer:%d\n",out);
    sleep(1);
  }
}

void* productor(void* arg)
{
  auto rq=(RingQuene<int>*)arg; 
  while(1)
  {
    int in=rand()%100+1;
    rq->push(in);
    printf("product:%d\n",in);
  }
}
int main()
{
  RingQuene<int>* rq=new RingQuene<int>();
  pthread_t c,p;
  srand((unsigned long)time(nullptr));
  pthread_create(&c,nullptr,consumer,rq);
  pthread_create(&p,nullptr,productor,rq);

  pthread_join(c,nullptr);
  pthread_join(p,nullptr);
  return 0;
}
